﻿#region Imports
using System;
using System.Globalization;
using System.Windows.Data;
using CommonUtilities.Extensions;
using OneStopProgrammingMatrix.Cache;
#endregion

namespace OneStopProgrammingMatrix.Converters
{
    public class MatrixGroupMnemonicConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return FormatName(value, value, parameter);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }

        internal static object FormatName(object target, object reference, object parameter)
        {
            if (reference as string != DataCache.sMyApps)
                return (parameter as string == "_" ? "_" : "") + (target as string).RemoveText("_");
            else if (reference as string == DataCache.sMyApps && target as string != DataCache.sMyApps && !(reference as string).IsNullOrEmpty())
                return "_" + (target as string).RemoveText("_");

            return target;
        }
    }
}
